package com.wxq.workpad

import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import com.samluys.statusbar.StatusBarUtils
import com.wxq.workpad.base.BaseActivity
import com.wxq.workpad.base.BaseFragment
import com.wxq.workpad.databinding.ActivityHomeActiviryBinding
import com.wxq.workpad.utils.FragmentChangeManager

class HomeActiviry : BaseActivity<ActivityHomeActiviryBinding>() {
    var baseFragments: MutableList<Fragment> = ArrayList()
   // fragment 管理类
    lateinit var fragmentChangeManager: FragmentChangeManager

    override fun initView(instanceState: Bundle?) {
        StatusBarUtils.transparencyBar(this@HomeActiviry)
        StatusBarUtils.StatusBarIconDark(this@HomeActiviry)

        binding.rlBottom0.setOnClickListener{
            updateSelect(0)
            fragmentChangeManager.showCurrentFragment(0)
        }
        binding.rlBottom1.setOnClickListener{
            updateSelect(1)
            fragmentChangeManager.showCurrentFragment(1)
        }

        binding.rlBottom2.setOnClickListener{
            updateSelect(2)
            fragmentChangeManager.showCurrentFragment(2)
        }

//        binding.rlBottom3.setOnClickListener{
//            updateSelect(3)
//            fragmentChangeManager.showCurrentFragment(2)
//        }


    }





    override fun initData() {
        baseFragments.add(HomeFragment.newInstance())
//        baseFragments.add(MyFragment.newInstance())
        baseFragments.add(MyFragment.newInstance())
        baseFragments.add(MyFragment.newInstance())
        fragmentChangeManager=   FragmentChangeManager(getSupportFragmentManager(), R.id.fl_maintab, baseFragments!!);

        updateSelect(0)



    }

    private fun updateSelect(i: Int) {
      // 还原所有
        binding.bottomTv0.setTextColor(ContextCompat.getColor(mContext, R.color.color_818484))
        binding.bottomTv1.setTextColor(ContextCompat.getColor(mContext, R.color.color_818484))
        binding.bottomTv2.setTextColor(ContextCompat.getColor(mContext, R.color.color_818484))
        binding.bottomTv3.setTextColor(ContextCompat.getColor(mContext, R.color.color_818484))

        binding.bottomIv0.setBackgroundResource(R.mipmap.index_n)
        binding.bottomIv1.setBackgroundResource(R.mipmap.app_n)
        binding.bottomIv2.setBackgroundResource(R.mipmap.my_n)
//        binding.bottomIv3.setBackgroundResource(R.mipmap.my_n)



        if (i==0) {
            binding.bottomTv0.setTextColor(ContextCompat.getColor(mContext, R.color.color_4474c3))
            binding.bottomIv0.setBackgroundResource(R.mipmap.index_sel)
        }
        if (i==1) {
            binding.bottomTv1.setTextColor(ContextCompat.getColor(mContext, R.color.color_4474c3))
            binding.bottomIv1.setBackgroundResource(R.mipmap.app_sel)
        }
        if (i==2) {
            binding.bottomTv2.setTextColor(ContextCompat.getColor(mContext, R.color.color_4474c3))
            binding.bottomIv2.setBackgroundResource(R.mipmap.my_sel)
        }
//        if (i==3) {
//            binding.bottomTv3.setTextColor(ContextCompat.getColor(mContext, R.color.color_4474c3))
//            binding.bottomIv3.setBackgroundResource(R.mipmap.my_sel)
//        }


    }

    companion object {

        @JvmStatic
        fun naveToActivity(context: Context) {
            val intent = Intent(context, HomeActiviry::class.java)
            context.startActivity(intent)
        }
    }
}